package me.boot.db.mybatis.template.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.boot.db.mybatis.annotation.WriteTransactional;
import me.boot.db.mybatis.template.SuperMapper;
import me.boot.db.mybatis.template.SuperService;
import me.boot.db.mybatis.template.entity.Entity;

import java.io.Serializable;
import java.util.List;

public abstract class SuperServiceImpl<
        ID extends Serializable,
        T extends Entity<ID>,
        M extends SuperMapper<T>>
        extends ServiceImpl<M, T>
        implements SuperService<ID, T> {

    @Override
    public ID insertIgnore(T entity) {
        baseMapper.insertIgnore(entity);
        return entity.getId();
    }

    @WriteTransactional
    @Override
    public int insertIgnoreBatch(List<T> entityList) {
        return baseMapper.insertIgnoreBatch(entityList);
    }

    @WriteTransactional
    @Override
    public int insertBatch(List<T> entityList) {
        return baseMapper.insertBatch(entityList);
    }

    @WriteTransactional
    @Override
    public boolean updateAllById(T entity) {
        return baseMapper.updateAllById(entity) > 0;
    }

}
